| Total Complexity | 4 |
| Total Lines | 23 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import Tweet from '../entities/Tweet'; |
||
| 8 | |||
| 9 | export default class Like extends AbstractAction { |
||
| 10 | async run(args: runLikeArgs): Promise<void> { |
||
| 11 | const {tweet, onSuccess} = args; |
||
| 12 | |||
| 13 | this.debug(`Liking tweet with id: '${tweet.rawTweet.id_str}' ...`); |
||
| 14 | const result = await this.twit.post('favorites/create', { |
||
| 15 | id: tweet.rawTweet.id_str |
||
| 16 | }); |
||
| 17 | |||
| 18 | if (this.isSuccessResponse(result)) { |
||
| 19 | this.debug('Liked!'); |
||
| 20 | |||
| 21 | if (onSuccess) { |
||
| 22 | onSuccess(tweet); |
||
| 23 | } |
||
| 24 | } else { |
||
| 25 | this.debug('Cannot like.'); |
||
| 26 | if (Helper.objectExists(result.resp.statusMessage)) { |
||
| 27 | this.debug(result.resp.statusMessage); |
||
| 28 | } |
||
| 29 | |||
| 30 | throw new Error('Cannot like'); |
||
| 31 | } |
||
| 33 | } |